﻿@{
    Layout = null;
}
@using CNKI.TPI.Web.Admin.Model;
@using CNKI.TPI.Web.Base
<script>
    //全选
    function subjectcheckall(e) {
        if ($(e).attr("checked") == "checked") {
            $(".checkboxsubject input[type='checkbox']").each(function () {
                $(this).attr("checked", "checked");
            })
        }
        else {
            $(".checkboxsubject input[type='checkbox']").each(function () {
                $(this).removeAttr("checked", "checked");
            })
        }
    }
    $(".checkboxsubject input[type='checkbox']").click(function () {
        //循环判断列表中的checkbox，如果全部选中则全选框呈勾选状态
        var m = 0;
        if ($(this).attr("checked") != "checked") {
            $("input.subjectall").removeAttr("checked", "checked");
        }
        else {
            $(".checkboxsubject input[type='checkbox']").each(function () {
                if ($(this).attr("checked") != "checked") {
                    m = 1;
                }
            })
            if (m == 1) {
                $("input.subjectall").removeAttr("checked", "checked");
            }
            else {
                $("input.subjectall").attr("checked", "checked");
            }
        }

    })
    //删除 多选
    function delsubjectlist() {
        var ckbs = $(".checkboxsubject input[type='checkbox']:checked");
        if (ckbs.size() == 0) {
            messageAlert("请选择要删除的记录！");
            return;
        }
        confirmDialog('确定要删除吗?', function () {
            var checkedstr = [];
            ckbs.each(function () {
                checkedstr.push($(this).val());
            })
            var delurl = "@Html.Raw(Url.Action("DelCLSQuery", "Admin_Topic"))";
            var data = { "sysidstr": checkedstr.toString() };
            dealdata(delurl, data);
        })

    }

    //删除
    function delsubject(sysid) {
        var delurl = "@Html.Raw(Url.Action("DelCLSQuery", "Admin_Topic"))";
        var data = { "sysidstr": sysid };
        confirmDialog('确定要删除吗?', function () {
            dealdata(delurl, data);
        })
    }
    //调用controll
    function dealdata(urlstr, datastr) {
        $.ajax({
            type: "POST",
            url: urlstr,
            data: datastr,
            success: function (m) {
                if (m == "True") {
                    messageAlert("操作成功！");
                    ajaxLoad('initload', "@Html.Raw(Url.Action("CategoryDataList", "Admin_Topic"))?name="
                        + escape($("#ClsName").val()) + "&code=" + $("#ClsCode").val() + "&navName=" + escape($("#NavName").val()) + "&navCode=" + $("#NavCode").val())
                }
                else {
                    messageAlert("操作失败！");
                }
            },
            error: function (e)
            { }
        })
    }

    function dealchecked(checkedsub, checkedparent) {
        var m = 0;
        $(checkedsub).each(function () {
            if ($(this).attr("checked") != "checked") {  //遍历判断是否存在没有选中的记录
                m = 1;
            }
        })
        if (m == 1) {
            $(checkedparent).removeAttr("checked", "checked");
        }
        else {
            $(checkedparent).attr("checked", "checked");
        }
    }

    function setQuery() {
            var str = $("#CodeGrade").val();
            var name = myTree.getItemText(str);
            ajaxLoad('initload', "@Html.Raw(Url.Action("ClsNodeQueryEdit", "Admin_Topic"))?name=" + escape($("#ClsName").val()) + "&code=" + $("#ClsCode").val() + "&navcode=" + $("#NavCode").val()+ "&navname=" + escape($("#NavName").val()))
    }
</script>
<table width="100%" cellspacing="0" cellpadding="0" border="0" class="table table-grey">
    <thead>
        <tr class="thead">
            <th class="tdnum">
                <input type="checkbox" class="subjectall" value="" name="" onclick="subjectcheckall(this)">序号</th>
            <th class=''>数据库名称</th>
             <th class=''>检索条件</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        @{if (ViewBag.QueryList != null)
          {
              int sortno = ViewBag.PageSize * (ViewBag.PageNow - 1) + 1;
              foreach (SYS_CMS_TOPIC_CLS_QUERY item in ViewBag.QueryList)
              {
                  string str = "even";
                  if (sortno % 2 == 0)
                  {
                      str = "odd";
                  }
            <tr class='@str'>
                <td class="checkboxsubject">
                <input type="checkbox" value="@item.SYSID">@sortno</td>
                <td style="width:200px"><a class="atitle" title="@ColumnAliasHelper.GetContentNoRed(item.DBName)">@Html.Raw(ColumnAliasHelper.SubContent(item.DBName, 20))</a></td>
                <td style="width:400px">@item.Query</td>
                <td class="tc">
                    <a onclick="delsubject('@item.SYSID')" href="javascript:void(0)">删除</a>
                </td>
            </tr>
                  sortno = sortno + 1;
              }
          }

        }
    </tbody>
</table>

@*//分页*@
<div class="pagenav pagenav-02">
    @*上一页*@
    @if (ViewBag.TotalPage > 0)
    {
        if (ViewBag.PageNow != 1)
        {
            int thispage = ViewBag.PageNow - 1;
        <a href="javascript:void(0);" class="page-prev" onclick="searchPageNew('@thispage')" >上一页</a>
        }
        else
        {
        <a href="javascript:return false;"  onclick="return false" class="page-prev disable">上一页</a>
        }
@*循环初始化页码*@
        foreach (string numpage in ViewBag.PageList)
        {
            if (numpage != "0")
            {
                int m = int.Parse(numpage);
                if (m == ViewBag.PageNow)
                {
        <a href="javascript:void(0);" class="active" onclick="searchPageNew('@numpage')">@numpage</a>
                    
                }
                else
                {
        <a href="javascript:void(0);" onclick="searchPageNew('@numpage')">@numpage</a>
                }

            }
            else
            {
        <i class="iconfont icon-dian2"></i>
            }

        }
@*下一页*@
        if (ViewBag.TotalPage > 0 && ViewBag.PageNow != ViewBag.TotalPage)
        {
            int nextpage = ViewBag.PageNow + 1;
        <a href="javascript:void(0);" class="page-next" onclick="searchPageNew('@nextpage')" >下一页</a>
        }
        else
        {
        <a href="javascript:return false;"  onclick="return false" class="page-prev disable">下一页</a>
        }
    }
    @if (@ViewBag.Count == 0)
    {
        <label>暂无数据！</label>
        
    }
    else
    {
          
        <label>共 </label>
        <label>@ViewBag.Count </label>
        <label>条数据 </label>
    }
</div>
<div class='posr' style="padding-bottom: 20px">

    <a class="btn btn-m btn-submit btn-defa-f" href="javascript:void(0);" onclick="setQuery()">配置</a>
    <a class="btn btn-m btn-submit btn-defa-f" href="javascript:void(0);" onclick="delsubjectlist()">删除</a>
          <a class="btn btn-m btn-prim-f" href="javascript:void(0);" onclick="backlist()">返回</a>
</div>
